package com.wtone.platform.gat.images.gat.core;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: aiLin
 * @Date: 2020/3/31 14:25
 * @desc: result code mag data
 */
@Slf4j
public class R extends HashMap<String, Object> {

	private static final long serialVersionUID = -8157613083634272196L;

	public static final int SUCCESS = 200;

	public static final int ERROR = 500;

	public R() {
		put("code", 200);
		put("msg", "success");
	}

	public static R error() {
		return error(500, "未知异常，请联系管理员");
	}

	public static R error(String msg) {
		return error(500, msg);
	}

	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	/***
	 * {
	 *   "msg": "success",
	 *   "code": 200,
	 *   "data": "设备：<10.6.254.15> 释放sdk资源成功"
	 * }
	 */
	public static R ok(String msg) {
		R r = new R();
		//r.put("msg", msg);
		r.put("data", msg);
		return r;
	}

	public static R data(Object obj) {
		R r = new R();
		r.put("data", obj);
		return r;
	}

	public static R okToMap(Map<String, String> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}

	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}

	public static R ok() {
		return new R();
	}

	@Override
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}

}